/**
 * Created by Administrator on 2017-07-06.
 */
// 引入自定义函数参考页面
import _ from 'lodash'
import md5 from '../../../static/MD5'
export default {
    install (Vue, options) {
        Vue.prototype.axiosDownloadHeaders = () => {
            let timestamp = new Date().getTime()
            timestamp = timestamp + ''
            return {
                Authorization: localStorage.AuthorizationToken2,
                timestamp: timestamp,
                loginType: '1',
                signature: md5(localStorage.AuthorizationToken2 + timestamp + localStorage.AuthorizationTokenKey).toUpperCase()
            }
        } // 返回axios下载的header
        Vue.prototype.dateToString2 = (date) => {
            return date.getFullYear() + '-' + (date.getMonth() + 1).toString() + '-' + (date.getDate()).toString() + ' 00:00:00'
        } // date转字符串
        Vue.prototype.dateToString3 = (date) => {
            return date.getFullYear() + '-' + (date.getMonth() + 1).toString() + '-' + (date.getDate()).toString() + ' 23:59:59'
        } // date转字符串
        Vue.prototype.dateToString4 = (date) => {
            return date.getFullYear() + '-' + (date.getMonth() + 1).toString() + '-' + (date.getDate()).toString() +
                ' ' + (date.getHours()).toString() + ':' + (date.getMinutes()).toString() + ':' + (date.getSeconds()).toString()
        } // date转字符串

        Vue.prototype.isChineseChar = (str) => {
            let reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/
            return reg.test(str)
        } // 验证非汉字，汉字为true

        Vue.prototype.isNumChar = (str) => {
            let reg = new RegExp('^[0-9]*$')
            return !reg.test(str)
        } // 验证非数字字，数字为false

        Vue.prototype.swap = (arr, index1, index2) => {
            arr[index1] = arr.splice(index2, 1, arr[index1])[0]
            return arr
        } // 数组元素交换

        Vue.prototype.swapUp = (arr, $index) => {
            if ($index === 0) {
                return
            }
            Vue.prototype.swap(arr, $index, $index - 1)
        } // 数组元素上移

        Vue.prototype.swapDown = (arr, $index) => {
            if ($index === arr.length - 1) {
                return
            }
            Vue.prototype.swap(arr, $index, $index + 1)
        } // 数组元素下移

        Vue.prototype.copyArr = (arr) => {
            return _.cloneDeep(arr)
        } // 数组深拷贝
        // ****************** 打印方法*****************************************
        // Vue.prototype.$C = (x) => {
        // 	console.log('打印方法：' + x)
        // }
        // ****************** 嵌套打印方法*****************************************
        // Vue.prototype.$XX = (x) => {
        // 	Vue.prototype.$C(x)
        // }
        Vue.prototype.$ND = () => {
            let date = new Date()
            let Y = date.getFullYear()
            let m = date.getMonth() + 1
            let d = date.getDate()
            // let H = date.getHours()
            // let i = date.getMinutes()
            // let s = date.getSeconds()
            if (m < 10) {
                m = '0' + m
            }
            if (d < 10) {
                d = '0' + d
            }
            // if (i < 10) {
            //     i = '0' + i
            // }
            // if (s < 10) {
            //     s = '0' + s
            // }
            return Y + '-' + m + '-' + d
        }
        Vue.prototype.$NDT = (add) => {
            let date = new Date()
            let Y = date.getFullYear() + add
            let m = date.getMonth() + 1
            let d = date.getDate()
            // let H = date.getHours()
            // let i = date.getMinutes()
            // let s = date.getSeconds()
            if (m < 10) {
                m = '0' + m
            }
            if (d < 10) {
                d = '0' + d
            }
            // if (i < 10) {
            //     i = '0' + i
            // }
            // if (s < 10) {
            //     s = '0' + s
            // }
            return Y + '-' + m + '-' + d
        }
        // *******************时间格式化的方法*************************************
        Vue.prototype.$F = (dateNum) => {
            if (!dateNum) {
                return ''
            }
            let date = new Date(parseInt(dateNum))
        	let Y = date.getFullYear()
        	let m = date.getMonth() + 1
        	let d = date.getDate()
        	let H = date.getHours()
        	let i = date.getMinutes()
        	let s = date.getSeconds()
        	if (m < 10) {
        		m = '0' + m
        	}
        	if (d < 10) {
        		d = '0' + d
        	}
        	if (i < 10) {
        		i = '0' + i
        	}
        	if (s < 10) {
        		s = '0' + s
        	}
        	return Y + '-' + m + '-' + d + ' ' + H + ':' + i + ':' + s
        }
        Vue.prototype.$FAddY = (dateNum, addYear) => {
            if (!dateNum) {
                return ''
            }
            let date = new Date(parseInt(dateNum))
        	let Y = date.getFullYear() + addYear
        	let m = date.getMonth() + 1
        	let d = date.getDate()
        	let H = date.getHours()
        	let i = date.getMinutes()
        	let s = date.getSeconds()
        	if (m < 10) {
        		m = '0' + m
        	}
        	if (d < 10) {
        		d = '0' + d
        	}
        	if (i < 10) {
        		i = '0' + i
        	}
        	if (s < 10) {
        		s = '0' + s
        	}
        	return Y + '-' + m + '-' + d + ' ' + H + ':' + i + ':' + s
        }
        Vue.prototype.$FAddYS = (dateNum, addYear) => {
            if (!dateNum) {
                return ''
            }
            let date = new Date(parseInt(dateNum))
        	let Y = date.getFullYear() + addYear
        	let m = date.getMonth() + 1
        	let d = date.getDate()
        	if (m < 10) {
        		m = '0' + m
        	}
        	if (d < 10) {
        		d = '0' + d
        	}
        	return Y + '-' + m + '-' + d
        }
        Vue.prototype.$FS = (dateNum) => {
            if (!dateNum) {
                return ''
            }
            let date = new Date(parseInt(dateNum))
        	let Y = date.getFullYear()
        	let m = date.getMonth() + 1
        	let d = date.getDate()
        	if (m < 10) {
        		m = '0' + m
        	}
        	if (d < 10) {
        		d = '0' + d
        	}
        	return Y + '-' + m + '-' + d
        }
        Vue.prototype.$overTime = (dateNum) => {
            if (parseInt(new Date().getTime()) > dateNum) {
                return false
            } else {
                return true
            }
        }
        // *******************时间格式化的方法*************************************
        Vue.prototype.$IN7DAY = (dateNum) => {
            let nowDate = Date.parse(new Date())
            let less7Days = dateNum - (7 * 24 * 60 * 60 * 1000)
            if (nowDate < dateNum && less7Days < nowDate) {
                return true
            } else {
                return false
            }
        }
        Vue.prototype.$overTenYear = (dateNum1, dateNum2) => {
            let date = new Date(parseInt(dateNum1))
            let Y = date.getFullYear() + 10
            date.setFullYear(Y)
            if (date.getTime() > dateNum2) {
                return false // 十年以内
            } else {
                return true // 超过十年
            }
        }
    }
}
